<template>
  <div id="selete"> 
    <input type="text" class="single-title" v-model="data.headerName">
    <draggable 
      v-model="data.configDtos"
      @end="handleEnd"
      animation="1000"
      handle=".mover"
    >
      <transition-group>
        <div v-for="(item, index) in data.configDtos" :key="index" class="option">
          <i class="icon_wj1 icon_select"></i> 
          <input type="text" class="single-option-title" v-model="item.configName">
          <a-tooltip title="删除选项"><a-icon type="close" @click="delOption(index)" class="del_op"/></a-tooltip>
          <a-tooltip title="移动选项"><a-icon type="border-outer" class="mover" style="margin-left: 10px"/></a-tooltip>
        </div>
      </transition-group>
    </draggable>
    <div>
      <a v-if="isFocus" @click="addOption">添加选项</a>
    </div>
  </div>
</template>

<script>
import Draggable from 'vuedraggable'
export default {
  props: ['data'],
  data() {
    return {
      isFocus: true
    }
  },
  components: {
    Draggable
  },
  methods: {
    addOption() {
      this.data.configDtos.push({
        configName: `选项${this.data.configDtos.length + 1}`,
        configNumber: this.data.configDtos.length +1,
      })
    },
    delOption(val) {
      this.data.configDtos.splice(val,1)
    },
    handleEnd() {
      this.$emit('changeOp', this.$parent.order, this.data.configDtos)
    }
  }
}
</script>

<style lang="less">
@import './style/common.css';
  #selete {
    .single-title {
      display: inline-block;
      border: none;
      font-size: 18px;
      margin-bottom: 5px;
      // color: 
    }
    .option {
      display: flex;
      margin-bottom: 5px;
      .single-option-title {
        border: none;
      }
      .mover{
        &:hover {
          color: blue;
        }
        // background-color: #fdfdfd;
        cursor: move;
        // padding:3px 6px;
      }
      .del_op {
        &:hover {
          color: red;
        }
      }
    }
  }
</style>